package com.runfast.waimai.web.controller.activity;

import com.alibaba.fastjson.JSONArray;
import com.runfast.common.web.entity.Result;
import com.runfast.waimai.dao.model.RunfastActivity;
import com.runfast.waimai.dao.model.RunfastActivityTarget;
import com.runfast.waimai.dao.model.RunfastGoodsSellType;
import com.runfast.waimai.service.RunfastActivityService;
import com.runfast.waimai.service.RunfastActivityTargetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ${DESCRIPTION} 活动商品信息（单品活动--活动商品规格对应关系，满减、新客户立减、配送费活动---活动商家对应关系）
 *
 * @author chenzheng
 * @create 2018-05-18 15:28
 **/
@RestController("activityTargetController")
@RequestMapping("/server/activityTarget")
public class ActivityTargetController {
    @Autowired
    private RunfastActivityService runfastActivityService;
    @Autowired
    private RunfastActivityTargetService runfastActivityTargetService;
    /**
     * 活动商品信息列表带分页的
     */
   /* @GetMapping("/list")
    //@RequiresPermissions("server:goodsSellType:list")
    public Result list(@PageableDefault Pageable pageable, Map<String, Object> params){

        RunfastGoodsSellTypeExample example=new RunfastGoodsSellTypeExample();
        //List<RunfastGoodsSellType> list=runfastGoodsSellTypeService.selectByExampleWithPageable(example,pageable);
        //Integer total=runfastGoodsSellTypeService.countByExampleWithPageable(example,pageable);
        Map<Object,Object> map=new HashMap<Object, Object>();
        //map.put("list",list);
        //map.put("total",total);
        return Result.ok(null,map);
    }*/

    /**
     * 活动商品信息列表
     */
    @GetMapping("/select")
    //@RequiresPermissions("server:goodsSellType:select")
    public Result select(){
        //List<RunfastGoodsSellType> list = runfastGoodsSellTypeService.selectByExample(null);
        //return Result.ok(null,list);
        return null;
    }

    /**
     * 保存活动商品信息
     */
    @PostMapping("/save")
    public Result save(String targets,Integer activityId){
        RunfastActivity activity=new RunfastActivity();
        if(targets==null){return  Result.fail(null,"活动关联信息不能为空！");}
        if(activityId !=null){
            activity=runfastActivityService.selectByPrimaryKey(activityId);
            if(activity.getType()==2||activity.getType()==4){
                //单品活动
                List<RunfastActivityTarget> list=(List<RunfastActivityTarget>) JSONArray.parseObject(targets,RunfastActivityTarget.class);
                if(list.size()>0){
                    for(RunfastActivityTarget target:list){
                        runfastActivityTargetService.insertSelective(target);
                    }
                }


            }else{



            }

        }





        return Result.ok(null);
    }

    /**
     * 修改活动商品信息
     */
    @PostMapping("/update")
    //@RequiresPermissions("server:goodsSellType:update")
    public Result update(@RequestBody RunfastGoodsSellType type){
        //runfastGoodsSellTypeService.updateByPrimaryKeySelective(type);
        return Result.ok(null);
    }

    /**
     * 删除活动商品信息---暂时不实现
     */
    /*@PostMapping("/delete")
    @RequiresPermissions("sys:role:delete")
    public R delete(@RequestBody Long[] roleIds){
        sysRoleService.deleteBatch(roleIds);

        return R.ok();
    }*/







}
